package com.example.demo.repository;


import com.example.demo.entity.Activity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ActivityRepository extends JpaRepository<Activity,Integer> {
    //@Query(value = "select * from activity where NAME = %?1; ",nativeQuery = true)
    @Query(value = "select * from activity where NAME = %?1 ",nativeQuery = true)
    Activity findByName(String name);

    //@Query(value = "select * from activity where creator_id = %?1; ",nativeQuery = true)
    @Query(value ="select * from activity where creator_id = %?1 ",nativeQuery = true)
    List<Activity> findByCreator(Integer creator_id);

    //@Query(value = "select * from activity where NAME like %?1 ;",nativeQuery = true)
    @Query(value ="select * from activity where NAME like %?1 ",nativeQuery = true)
    List<Activity> getByNameLike(String keystring);

    @Query(value ="SELECT * FROM activity WHERE name like %:keystring% ",nativeQuery = true)
    Page<Activity> getByname(String keystring, Pageable pageable);

    @Query(value ="SELECT * FROM activity WHERE creator_id IN (:ids)",nativeQuery = true)
    Page<Activity> getByCreatorId(List<Integer> ids,Pageable pageable);

    @Query(value ="SELECT * FROM activity ORDER BY joiner_number DESC LIMIT 5;",nativeQuery = true)
    List<Activity> findhot();
}
